package com.jn.prototype.improve;

/**
 * 原型模式
 *
 * @author 江南大学1033190417
 * @date 2022/4/11 17:08
 */
public class Sheep implements Cloneable{
    private String name;

    private int age;

    private String color;


    public Sheep(String name, int age, String color) {
        this.name = name;
        this.age = age;
        this.color = color;
    }

    public Sheep() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    @Override
    public String toString() {
        return "姓名："+name+"\t年龄："+age+"\t颜色："+color;
    }

    //克隆该实例,使用默认的克隆方法
    @Override
    protected Object clone() {
        Sheep sheep=null;
        try {
            sheep=(Sheep) super.clone();
        }catch (Exception e){
            e.printStackTrace();
        }
        return sheep;
    }
}
